//
//  WWCommonUtility.m
//  WhatWeather
//
//  Created by byn on 15/10/11.
//  Copyright © 2015年 byn. All rights reserved.
//

#import "WWCommonUtility.h"
#import <CommonCrypto/CommonDigest.h>
#import <CommonCrypto/CommonHMAC.h>

@implementation WWCommonUtility

+ (NSString *)hmacSha1WithKey:(NSString *)key data:(NSString *)data{
    const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding];
    const char *cData = [data cStringUsingEncoding:NSUTF8StringEncoding];
    
    char hmac[CC_SHA1_DIGEST_LENGTH];
    
    CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), hmac);
    NSData *hmacData = [[NSData alloc] initWithBytes:hmac length:CC_SHA1_DIGEST_LENGTH];
    return [[NSString alloc] initWithData:[hmacData base64EncodedDataWithOptions:0] encoding:NSUTF8StringEncoding];
}

+ (NSString *)getWeekDayOfToday : (NSInteger)index {
    NSArray *weekOfDayArray = [[NSArray alloc] initWithObjects:@"周日",@"周一",@"周二",@"周三",@"周四",@"周五",@"周六", nil];
    if(index > [weekOfDayArray count] || index <= 0) {
        return nil;
    }
    
    return [weekOfDayArray objectAtIndex:index-1];
}

@end






































